import { MiniGameBaseController } from "../../MiniGameBaseController";
import { Hook } from "../Obj/Hook";
import { HookState } from "../defin/HookState";
import { FishingGlobal } from "../FishingGlobal";
import { MsgManager } from "../../../../manager/MsgManager";
import { Language } from "../../../../../../extend/language/Language";
import { Cache } from "../../../../cache/Cache";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { FishingScene } from "../FishingScene";
import { MiniGameObject } from "../../MiniGameObject";
//class HookController
    
    export  class HookController extends MiniGameBaseController
    {
        constructor()
        {
            super();
            this.addListeners();
            return;
        }

        protected addListeners(): void
        {
            return;
        }

        protected removeListeners(): void
        {
            return;
        }

        protected startHook(): void
        {
            var loc1=_target as Hook;
            if (loc1.hookState == HookState.swing) 
            {
                if (!FishingGlobal.isHaveFishTime) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(41522));
                    return;
                }
                if (!FishingGlobal.isHaveFishHook) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(41523));
                    return;
                }
                if (Cache.instance.pack.fishPackCache.getBackPackIsFullOrNot()) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(41525));
                    return;
                }
                loc1.hookState = HookState.down;
                Dispatcher.dispatchEvent(new DataEvent(EventName.FishMiniGameFishStart));
            }
            return;
        }

        public autoRun(): void
        {
            var loc1=_target as Hook;
            var loc2=this.getSpeed();
            if (loc1.hookState == HookState.down) 
            {
                loc1.speed = loc2;
            }
            if (loc1.hookState == HookState.up) 
            {
                loc1.speed = -1 * loc2;
            }
            return;
        }

        protected getSpeed(): number
        {
            var loc1=20;
            var loc2=FishingScene.AREAHEIGHT - 40;
            var loc3=8;
            var loc4=3;
            var loc5=(_target as Hook).length;
            var loc6=(loc2 - loc5) / (loc2 - loc1);
            var loc7;
            return loc7 = loc4 + loc6 * loc6 * (loc3 - loc4);
        }

        public /* override */ set target(arg1: MiniGameObject)
        {
            if (typeof arg1 === "hook") 
            {
                super.target = arg1;
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose();
            this._speed = 0;
            this.removeListeners();
            return;
        }

        protected /* var */_speed: number=30;
    }
